#include "Ice.h"

const float Ice::FREEZING_TIME_LEVEL1 = 5;
const float Ice::FREEZING_TIME_LEVEL2 = 4;
const float Ice::FREEZING_TIME_LEVEL3 = 2.5;

const float Ice::PERCENT_SPEED_LOST = 0.3;


bool Ice::IsFreezingTimerStarted()
{
	return timer != 0;
}

void Ice::StartFreezingTimer()
{
	initTime = clock();
}

void Ice::ResetFreezingTimer()
{
	timer = 0;
	initTime = 0;
}

void Ice::Initialize(int level)
{
	switch(level)
	{
		case 1:
			Ice::currentFreezingTime = Ice::FREEZING_TIME_LEVEL1;
		break;

		case 2:
			Ice::currentFreezingTime = Ice::FREEZING_TIME_LEVEL2;
		break;

		case 3:
			Ice::currentFreezingTime = Ice::FREEZING_TIME_LEVEL3;
		break;
	}
}


void Ice::Update(Player player)
{
//	if (player.GetState() == Player::Freeze) return;
	
	if (player.GetCollisionRect().Intersects(Ice::GetCollisionRect()))
	{
		if (!IsFreezingTimerStarted())
			StartFreezingTimer();

		Vector2 newPlayerSpeed = player.GetSpeed() * Ice::PERCENT_SPEED_LOST;
		player.SetSpeed(newPlayerSpeed);
		timer = clock();

		if (initTime + currentFreezingTime < timer)
		{
		//	player.ChangeState(Freeze.GetInstance());
			ResetFreezingTimer();
		}
				
		return;
	}

	ResetFreezingTimer();
}